#pragma once
/*!
* \file  ui_slider.h
* \brief 
* 
*
* 
* \author patdz@qq.com
* \version 1.0
* \date 2014/06/21
*/
#include "ui_focusable_control.h"

_SSL_BEGIN
_SSUIL_BEGIN

#pragma warning(push)
#pragma warning(disable:4250)
#pragma warning(disable:4251)
enum UISliderType
{
	kSTypeNone,
	kSTypeHorz,
	kSTypeVert,
};

class SSUI_CLASS UISlider :
	public UIFocusableControl
{
public:
	UISlider();
	virtual ~UISlider();

	// base_control
public:
	virtual bool ApplyAttributes(IUIBuilderInterface *ui_builder, 
		IUIXMLDocumentInterface *xml_document, UIXmlNode node);
	virtual void AfterBuild(IUIBuilderInterface *ui_builder,
		IUIXMLDocumentInterface *xml_document, UIXmlNode node);
	virtual void OnRenderChilds(const UIRenderContext &rc)
	{
		__super::OnRenderChilds(rc);
	}

	virtual void OnRecalcChildsLayoutOnVisibleSizeChanged()
	{
		__super::OnRecalcChildsLayoutOnVisibleSizeChanged();
	}
protected:
	virtual void OnRecalcChildsLayoutOnSizeChange();

	// IUIEventReceiverInterface
public:
	virtual void DoEvent(UIEvent &evt);

	//
	//
public:
	void SetSliderType(UISliderType tp);
	bool SetRange(int min_v, int max_v);
	bool SetValue(int v);
	void GetRange(int &min_v, int &max_v) const;
	int GetValue() const;
	void SetChangeValueOfClickOutofThumb(int v);
	void SetUpDownConvertMode(bool f);

public:
	bool ScrollHome();
	bool ScrollEnd();
	bool ScrollPageUp();
	bool ScrollPageDown();
	bool ScrollLineUp();
	bool ScrollLineDown();
	bool ScrollByKey(tchar ch);

protected:
	bool SetThumbControlOnChilds(IUIControlInterface *thumb);

	double UnitLength();
	bool GetThumbLeftTop(int &left, int &top);
	bool GetThumbLeftTopOnDrag(int &left, int &top, UIPoint &mouse);

protected:
	bool DelegteOnThumbEvent(void* tag);

public:
	event_source OnValueChanged;

	//
protected:
	UISliderType slider_type_;
	weak_ptr<IUIControlInterface> thumb_;
	int min_value_;
	int max_value_;
	int value_;
	int change_value_click_outof_thumb_;
	int page_step_value_;
	int line_step_value_;
	bool draging_;
	UIPoint drag_mouse_pt_;
	UIPoint drag_thmub_pt_;
	bool ud_convert_;
};

#pragma warning(pop)

_SSUIL_END
_SSL_END
